在 VisualApplets 中的实现

在 VisualApplets 中实现的示例设计执行了几何变换、组合几何变换和 Distortion Correction 以及由图像矩控制的几何变换。几何变换是通过目标到源映射(即逆向映射)实现的。此方法对于保证发送到 PC 的目标图像中没有丢失像素至关重要 [Bur06]。我们基于算子 FrameBufferRandomRead 实现了逆向几何变换,并基于算子 PixelReplicator 实现了替代方案。这些差异将在以下小节中进行解释。在这些小节中,将详细介绍示例设计。

使用 FrameBufferRandomRead 的几何变换
简要说明

文件: \examples\Processing\Geometry\GeometricTransformation\GeometricTransformation_ FrameBufferRandomRead.va

默认平台: mE5-MA-VCL

简短说明

几何变换:使用算子 FrameBufferRandomRead 进行旋转、平移和 Scaling

在 VA 设计“Geometric Transformation_FrameBufferRandomRead.va”中,通过目标到源映射实现了几何变换。此方法对于保证发送到 PC 的目标图像中没有丢失像素至关重要 [Bur06]。 源图像的坐标 是通过对所有目标坐标进行逆向几何变换来计算的 。 在坐标位置 处, 使用算子以 1 的 Parallelism 读取源图像中的像素值 FrameBufferRandomRead 。该算子将每个像素单独存储在 DRAM 中,并逐个读取像素。当计算出的源图像坐标与源图像中的像素坐标不匹配时,线性插值有助于校正发送到 PC 的输出图像中的像素值。 如图 297 所示,您可以看到基本设计结构。

VA 设计“GeometricTransformation_FrameBufferRandomRead.va”的基本设计结构

图 297. VA 设计“GeometricTransformation_FrameBufferRandomRead.va”的基本设计结构


该设计由 Camera Link Base 配置中的相机接口(BaseGrayCamera_Camera)以及在其中执行采集图像的 Scaling、旋转和平移的 HierarchicalBox Geometric Transformation 组成。算子 ImageBuffer_Buffer 提供了存储图像的机会。通过 DMA(算子 DmaToPC_DMA0),图像被传输到 PC。

在 298 中,您可以看到 HierarchicalBox GeometricTransformation 的内容。 参数 IntParamTranslator、FloatParamReference 和 IntParamReference 让您可以非常方便地设置几何变换的相关参数(Scaling、旋转、平移和图像尺寸的值)。 Property 是图像 Height 和 Width、您希望在 x 和 y 方向上平移图像的像素数 (参数:Translatex 和 Translatey)以及在 x 和 y 方向上的缩放因子 Scalex 和 Scaley。您可以使用参数 Phi 以度数设置旋转角度。作为替代方案,您可以通过在 HierarchicalBox GeometricTransformation 上点击鼠标右键来设置这些 Properties。您可以在 图 298 中看到此框的内容。

HierarchicalBox“GeometricTransformation”的内容

图 298. HierarchicalBox“GeometricTransformation”的内容


即: SourceImage 以线性方式写入缓冲区 FrameBufferRandomRead。对于每个像素,其最近邻都保存在 2x2 内核中(HierarchicalBox NextNeighbours)). 目标图像的坐标 (式 21) 由 HierarchicalBox CreateBlankImage, CoordinateX 和 CoordinateY 中的算子 OutputImage (包含在 HierarchicalBox CoordinateTransformation中) 生成(参见图 299 和 300)。

HierarchicalBox CoordinateTransformation 的内容

图 299. HierarchicalBox CoordinateTransformation 的内容


HierarchicalBox OutputImage 的内容

图 300. HierarchicalBox OutputImage 的内容


这些坐标 can be rotated, translated and/or scaled in inverse direction according to eq. 21. 如上所述,旋转角 以及用于平移和 Scaling 的参数 和 可以通过传输参数设置相应的常数来选择。在图 301 中,您可以看到式的 VA 实现,并具备附加的 Scaling 功能。 21 。

HierarchicalBox InverseTransformation 的内容

图 301. HierarchicalBox InverseTransformation 的内容


逆变换产生的坐标即为源坐标 和 (式 21)。在 HierarchicalBox SplitFractionalAndIntegerBit (参见图 298) 中,这些坐标的整数和小数位部分被分离。与源图像中的像素位置对应的整数位部分 是算子的坐标输入 FrameBufferRandomRead (x 和 y 方向,参见图 298)。 该算子从源图像中对应坐标处读取像素值信息(Parallelism = 1)以及其邻近像素(参见上文)。 源坐标的小数位部分 和 对应于源图像中的亚像素位置。 利用这些信息以及源图像中邻近像素的像素值信息,目标图像中的真实像素值将在 HierarchicalBox 中进行双线性 插值 插值。有关插值过程的详细描述,请参见 [Bur06]。

在图 302 和 303 中,您可以看到几何变换示例中的源图像和目标图像。执行了 x 和 y 方向各 100 像素的平移以及 45° 的旋转。

源图像

图 302. 源图像 [Ope16a]


旋转和转换后的目标图像

图 303. 旋转和转换后的目标图像


使用图像矩进行几何变换
简要说明

文件: \examples\Processing\Geometry\GeometricTransformation\GeometricTransformation_ImageMoments.va

默认平台: mE5-MA-VCL

简短说明

几何变换:利用图像矩将对象旋转和平移至图像中心

在此示例设计中,利用图像矩确定 RGB 图像中物体的位置和旋转角度。执行旋转至水平 方向并平移至图像中心的操作。默认情况下,输入图像尺寸为 640x240 像素,输出图像尺寸为 256x128 像素。 在图 304 中,您可以看到基本设计结构。

VA 设计“GeometricTransformation_ImageMoments.va”的基本设计结构

图 304. VA 设计“GeometricTransformation_ImageMoments.va”的基本设计结构


该设计由 Camera Link base 配置的 RGB 相机接口(BaseRgbCamera_Camera)以及在其中执行采集图像旋转和平移的 HierarchicalBox Geometric Transformation 组成。通过在“Properties”下“右键单击”, 您可以设置输入和输出图像尺寸以及二值化阈值。此阈值与下文所述图像矩的计算相关。 几何变换通过目标到源映射完成(参见 节中的引言文本)。 通过 DMA(算子 DmaToPC_DMA0)将图像传输到 PC。在图 305 中,您可以看到 Geometric Transformation 的内容。

HierarchicalBox GeometricTransformation 的内容

图 305. HierarchicalBox GeometricTransformation 的内容


相对于水平位置的旋转角度和物体的重心 位置是通过在 HierarchicalBox ImageMoments 中对二值化图像(HierarchicalBox Binarization)计算图像矩来确定的。ImageMoments 的内容 等同于 VA 示例“ImageMoments.va”的箱 ImageMoments(参见 节中的图 325),但未计算物体偏心率。HierarchicalBox ImageMoments 的输出链路(从上到下)是 x 和 y 方向的重心位置以及旋转角度。 基于这些参数的源坐标计算(根据方程式 21) 包含在 HierarchicalBox CoordinateTransformation 中。 在 306 中,您可以看到此箱的内容。

HierarchicalBox CoordinateTransformation 的内容

图 306. HierarchicalBox CoordinateTransformation 的内容


在 HierarchicalBox 同步方式 中,x 和 y 方向的重心以及旋转的单像素值被扩展至由 HierarchicalBox 定义的输出图像尺寸 OutputImage中。该盒子的输出链接表示目标图像坐标 。在 HierarchicalBox 中 源坐标 和 根据方程式计算得出 21。如图 307 所示,您可以查看此盒子的内容。

HierarchicalBox InverseTransformation 的内容

图 307. HierarchicalBox InverseTransformation 的内容


该盒子中的设计结构类似于示例“GeometricTransformation_FrameBufferRandomRead.va”和“GeometricTransformation_PixelReplicator.va”中逆变换的实现。不同之处在于,x 和 y 方向的平移参数由重心与图像中心在 x 和 y 方向上的差值决定(参见盒子 Translation_x 和 Translation_y的内容)。旋转角(盒子 Phi的内容)由图像矩计算的结果定义。回到图 304中的基本设计结构。计算出的源图像坐标 和 代表盒子 CoordinateTransformation的输出链接 GeometricTransformation (参见图 308)中,使用算子 FrameBufferRandomRead 执行几何变换以及正确目标像素值的双线性插值,类似于示例“GeometricTransformation_FrameBufferRandomRead.va”(参见图。 298 在小节中 )。

HierarchicalBox GeometricTransformation 的内容

图 308. HierarchicalBox GeometricTransformation 的内容


对于图 309 中的示例对象,您可以在图 310 中看到经过方向和位置校正的目标图像。

源图像(尺寸:640x240 像素)

图 309. 源图像(尺寸:640x240 像素)


经过位置和方向校正的目标图像(尺寸:256x128 像素)

图 310. 经过位置和方向校正的目标图像(尺寸:256x128 像素)


使用 PixelReplicator 进行几何变换
简要说明

文件: \examples\Processing\Geometry\GeometricTransformation\GeometricTransformation_PixelReplicator.va

默认平台: mE5-MA-VCL

简短说明

几何变换:使用算子 PixelReplicator 进行旋转、平移和 Scaling

VisualApplets 设计示例“GeometricTransformation_PixelReplicator.va”执行的几何变换与示例“GeometricTransformation_FrameBufferRandomRead.va”相同,但性能更高。如上所述,算子 FrameBufferRandomRead 将每个像素单独存储在 DRAM 中并依次读取。在此示例中,特定数量的像素块存储在 DRAM 单元中。 如果待读取的像素与前一个像素不在同一单元中,示例设计才会从 DRAM 读取。图 311 中每个 DRAM 单元包含 8 个像素的示例展示了性能提升的概念。

示例:8 个像素存储在一个 DRAM 单元中

图 311. 示例:8 个像素存储在一个 DRAM 单元中


DRAM 块以绿色标出。要读取 9 个像素 a 到 i,您需要 3 个 DRAM 周期,而不是 9 个。在此我们实现了 3 的有效 Parallelism。 可以存储在一个 RAM 单元中的 8 位像素的最大数量为 32(marathon VCL 数据宽度:256 位)。RAM 单元块的 ROI 形状由几何变换的旋转角定义。在此示例中,默认选择 9x3 像素的 RAM 单元形状。 基本设计结构与图 297 中的设计结构相当,但没有算子 PARALLELdn_To1。HierarchicalBox GeometricTransformation 的内容也与示例“GeometricTransformation_FrameBufferRandomRead.va”中的对应框(图 298)相当。不同之处在于,算子 FrameBufferRandomRead 被替换为了 HierarchicalBox FrameBufferRandomRead_Par8。您可以在图 312 中看到其内容。

HierarchicalBox FrameBufferRandomRead_Par8 的内容

图 312. HierarchicalBox FrameBufferRandomRead_Par8 的内容


在框 CollectNeighbors 中,源图像被分割为子 ROI,这些子 ROI 定义了每个 RAM 单元的大小。此处选择了 9x3 的 RAM 单元大小。在 HierarchicalBox SplitAdressX 和 SplitAdressY 中,作为逆几何变换结果的源坐标的整数位部分(参见小节 和 中,作为逆几何变换结果的源坐标的整数位部分(参见小节 ) 分为两个组件。高位部分(的上方输出链路 SplitAdressX 和 SplitAdressY) 表示 DRAM 单元的位置,低位部分表示 DRAM 单元中的像素位置。如果在 HierarchicalBox Buffer (包含算子 FrameBufferRandomRead)中未决定在 HierarchicalBox RepeatDecider中复用先前的 DRAM 单元,则读取该 DRAM 单元的 DRAM 单元坐标。如果决定复用先前的单元,则需要复制 DRAM 单元的像素值。 此操作在 HierarchicalBox ReplicateValues 中进行, PixelReplicator的输出链接 ExtractSubKernel 算子使用作为 SplitAdressX 和 SplitAdressY 输出的像素坐标(下方输出链路),从 DRAM 单元中提取所需的像素值及其下一个相邻像素。 目标像素值的双线性插值计算方法与 .

几何变换和 Distortion Correction
简要说明

文件: \examples\Processing\Geometry\GeometricTransformation\GeometricTransformation_ DistortionCorrection.va

默认平台: mE5-MA-VCL

简短说明

几何变换:使用 PixelReplicator 算子进行旋转、平移、Scaling、畸变和梯形畸变矫正

VA 示例“GeometricTransformation_DistortionCorrection.va”是设计“GeometricTransformation_PixelReplicator.va”的扩展。 此外, 此设计还实现了畸变和梯形畸变矫正(根据公式 22 和公式 23)。在下文中,仅对相较于 “GeometricTransformation_PixelReplicator.va”的不同部分进行说明。图 313 展示了 基本设计结构。

VA 设计“GeometricTransformation_DistortionCorrection.va”的基本设计结构

图 313. VA 设计“GeometricTransformation_DistortionCorrection.va”的基本设计结构


来自 CameraLink Base 配置中的相机接口的灰度图像(最大尺寸:4096x4096 像素) (BaseGrayCamera_Camera)在 HierarchicalBox GeoTransAndDistCorr 中进行变换,并通过 DMA 传输到 PC (DmaToPC_DMA0)。该结构等同于设计“GeometricTransformation_FrameBufferRandomRead”和 “GeometricTransformation_PixelReplicator”。 GeoTransAndDistCorr 的结构等同于这两个设计的箱子 GeometricTransformation (参见图 298)。此处执行逆变换以及畸变和梯形畸变矫正。箱子 CoordinateTransformation(位于箱子 GeometricTransformation 中)的内容如图 314 所示。

HierarchicalBox CoordinateTransformation 的内容

图 314. HierarchicalBox CoordinateTransformation 的内容


等同于设计“GeometricTransformation_FrameBufferRandomRead”和 “GeometricTransformation_PixelReplicator”(小节 和 )目标坐标 根据公式进行逆变换。 21 带有附加的 Scaling(另请参阅章节 )。 利用逆变换得到的坐标,随后我们在 HierarchicalBoxes 中执行逆梯形畸变 (Keystone) 和 Distortion Correction KeystoneCorrrection 和 DistortionCorrection。这些框的内容如图 315 和图 314.

HierarchicalBox KeystoneCorrection 的内容

图 315. HierarchicalBox KeystoneCorrection 的内容


HierarchicalBox DistortionCorrection 的内容

图 316. HierarchicalBox DistortionCorrection 的内容


在这些框中实现了公式 22 和 公式 23 。框中的矩阵元素 m1 到 m9 Z_x, Z_y 和 N (参见图 315) 可以借助 OpenCV 库计算 [Ope16b]。对于示例图像 "Example.tif" (位于 \examples\Processing\Geometry\GeometricTransformation 下),您可以在同一位置的文本文件 "MatrixValues.txt" 中找到示例矩阵值。 对于图 314 中的 Distortion Correction 而言, 首先将坐标变换到相对于光学中心的坐标系中(CoordinateTransformation_x 和 CoordinateTransformation_y), 在大多数情况下,这就是图像中心。在 HierarchicalBox DistortionCoefficient 到光学中心的距离 (参见式 23) 会被计算出来。对于每个 随后,在查找表中会存在一个 Distortion Correction 参数 (参见图 317)。 该查找表是通过一个 Matlab 模块在外部创建的,您可以在 \examples\Processing\Geometry\GeometricTransformation \LUTDistortionCorrection.m 中找到它,并且畸变参数 和 是用 OpenCV 库 [Ope16b] 创建的。在“LUTDistortionCorrection.m”中,您可以找到针对示例图像“Example.tif”(位于 \examples\Processing\Geometry\GeometricTransformation 下)的校正参数 和 [Ope16a]。 然后,将该系数 与坐标 和 相乘(图 314)。随后,生成的畸变坐标被变换回相对于“左上图像角”的坐标系(参见框 CoordinateTransformation_x 和 CoordinateTransformation_y)。结果即为源图像坐标 和 。HierarchicalBox LimitCoordinateValues 相乘(图 314) 为变换后的图像坐标设置边界条件。在分离整数和小数位部分 (参见图 SplitFractionalAndIntegerBit 中的框 298)后,从源图像中读取计算出的相应整数源图像坐标处的像素值。 小数位部分用于根据 [ 插值] 进行双线性插值(参见Bur06]), 以校正由于源图像中像素间位置而导致的输出图像中的像素值。信号通过 DMA 传输到 PC。 为了进行演示,您可以在图 318, 319 和 320 中看到畸变的源图像、经过梯形畸变和 Distortion Correction 的目标图像以及经过旋转和 Distortion Correction 的目标图像。

HierarchicalBox DistortionCoefficient 的内容

图 317. HierarchicalBox DistortionCoefficient 的内容


示例源图像

图 318. 示例源图像 [Ope16a]


经过畸变和梯形畸变矫正的目标图像

图 319. 经过梯形畸变和 Distortion Correction 校正的目标图像


经过旋转、畸变和梯形畸变矫正的目标图像

图 320. 经过旋转、梯形畸变和 Distortion Correction 校正的目标图像


Distortion Correction
简要说明

文件: \examples\Processing\Geometry\GeometricTransformation\DistortionCorrection.va

默认平台: mE5-MA-VCL

简短说明

在此示例设计中,实现了 Distortion Correction。

在设计“DistortionCorrection.va”中,实现了符合公式 22 的 Distortion Correction。它类似于设计“GeometricTransformation_DistortionCorrection.va”中的实现,但未执行几何变换和梯形畸变矫正。基本设计结构如图 321 所示。

VA 设计“DistortionCorrection.va”的基本设计结构

图 321. VA 设计“DistortionCorrection.va”的基本设计结构


该设计由用于 Camera Link Base 配置灰度相机的接口、缓冲区模块、HierarchicalBox DistortionCorrection 以及 DmaToPC 组成。灰度图像的 Distortion Correction 在 DistortionCorrection 中执行。其内容如图 322 所示。

HierarchicalBox DistortionCorrection 的内容

图 322. HierarchicalBox DistortionCorrection 的内容


该结构类似于 HierarchicalBox 的内容 GeometricTransformation (参见 图 298),位于 章节 的“GeometricTransformation_PixelReplicator.va”设计中。算子 FrameBufferRandomRead 已被替换为 HierarchicalBox FrameBufferRandomRd_Par8 ,这与“GeometricTransformation_PixelReplicator.va”和“GeometricTransformation_DistorationCorrection.va”中的做法相同 (参见章节 和 )。源图像被线性写入缓冲元素 FrameBufferRandomRd_Par8中。在该模块中,每个像素的三个最近邻域也与该像素一起存储(参见方框 CollectNeighbors 中的方框 FrameBufferRandomRd_Par8).在方框 CoordinateTransformation/ OutputImage 目标图像坐标 是通过算子 CreateBlankImage, CoordinateX 和 CoordinateY创建的。这些坐标根据公式 22 变换为源图像坐标 中的算子 InverseCorrection (参见方框 CoordinateTransformation)。其内容见图 323.

HierarchicalBox InverseCorrection 的内容

图 323. HierarchicalBox InverseCorrection 的内容


它等效于方框 DistortionCorrection 在 "GeometricTransformation_DistortionCorrection.va" 中的实现(参见图 316)。对于相对于图像中心的每个目标图像半径 ,在 HierarchicalBox 中选择一个查找表值 C_r DistortionCoefficient. C_r 将其与目标图像坐标相乘 根据等式 22 并变换回相对于第一个像素的坐标系(参见 CoordinateTransformation_x_1 和 CoordinateTransformation_y_1)。正如你在图 322 中所看到的,生成的源坐标在方框中被拆分为整数和小数部分 SplitFractionalAndIntegerBit。整数部分用于在相应的源图像坐标处读取源图像的像素,小数部分用于对最终结果进行双线性插值。然后,校正畸变后的图像通过 DMA 传输到 PC。